package com.twu.option;

import java.util.ArrayList;
import java.util.List;

import com.twu.bean.User;
import com.twu.util.OptionsUtil;

public class DisplayBooksOption implements Option
{
	private static List<String> allBooks;

	static
	{
		allBooks = new ArrayList<String>();
		allBooks.add("Thinking in JAVA");
		allBooks.add("Thinking in C++");
		allBooks.add("Thinking in Python");
	}

	private final Option subOption;
	private final User currentUser;

	public DisplayBooksOption(User currentUser)
	{
		this.currentUser = currentUser;
		subOption = new ReserveOption(allBooks);
	}

	public DisplayBooksOption()
	{
		this.currentUser = null;
		this.subOption = this;
	}

	@Override
	public String execute()
	{
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("All Books below:\n").append(displayAllBooks());
		return stringBuilder.toString();
	}

	@Override
	public String getTips()
	{
		return currentUser != null ? OptionsUtil.formattedOutput(allBooks) + "\n"
				+ "Input a book number to select the book to reserve" : "There is no option!";
	}

	@Override
	public Option selectOption(int option)
	{
		return subOption;
	}

	@Override
	public String toString()
	{
		return "Show all books";
	}

	private String displayAllBooks()
	{
		return (OptionsUtil.formattedOutput(allBooks));
	}

}
